#ifndef _ST7305_1P54_DRIVER_H_
#define _ST7305_1P54_DRIVER_H_
#include "driver/gpio.h"
#include "esp_err.h"
#include "ST7305_UI.h"
#include "esp_lcd_io_spi.h"

#define ST7305_COLOR_WHITE (0x00)
#define ST7305_COLOR_BLACK (0x01)

#define ST73XX_COLOR_BLACK ST7305_COLOR_BLACK
#define ST73XX_COLOR_WHITE ST7305_COLOR_WHITE

#ifdef __cplusplus
extern "C" {
#endif

//extern uint32_t frame_num;

class ST7305_1p54_driver : public ST7305_UI{
    public:
        ST7305_1p54_driver(gpio_num_t dcPin, gpio_num_t resPin, gpio_num_t csPin, gpio_num_t sclkPin, gpio_num_t sdinPin);
        ~ST7305_1p54_driver();
    
        void initialize();
        void fill(uint8_t data);
    
        void clearDisplay();
    
        void writePoint(uint16_t x, uint16_t y, bool enabled) override;
        void writePoint(uint16_t x, uint16_t y, uint8_t data) override;
    
        void display();
    
        void Initial_ST7305();
        void Low_Power_Mode();
        void High_Power_Mode();
        void display_on(bool enabled);
        void display_sleep(bool enabled);
        void display_Inversion(bool enabled);
        uint32_t frame_num;
        bool frame_update_done_flag = true;
    
    private:
        static bool frame_update_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx);
        void nonStaticFrame_update_done();
        const gpio_num_t DC_PIN;
        const gpio_num_t RES_PIN;
        const gpio_num_t CS_PIN;
        const gpio_num_t SCLK_PIN;
        const gpio_num_t SDIN_PIN;
        const uint8_t LCD_WIDTH;
        const uint8_t LCD_HIGH;
        const uint8_t LCD_DATA_WIDTH;
        const uint8_t LCD_DATA_HIGH;
        const uint16_t DISPLAY_BUFFER_LENGTH;
        esp_lcd_panel_io_handle_t lcd_io_handle = NULL;
    
        bool HPM_MODE = false;
        bool LPM_MODE = false;
    
        uint8_t* display_buffer;
    };

//bool frame_add(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx);

#ifdef __cplusplus
}
#endif

#endif